package com.example.kotlinstudy.knowledges


fun main() {
    println("===== Kotlin 基本类型演示与测试 =====")

    // 1. 声明所有基本类型变量（含无符号类型）
    val bool: Boolean = true

    val byteNum: Byte = 10
    val shortNum: Short = 300
    val intNum: Int = 12345
    val longNum: Long = 123_456_789L

    val uByteNum: UByte = 200.toUByte()
    val uShortNum: UShort = 60_000.toUShort()
    val uIntNum: UInt = 4_000_000_000u
    val uLongNum: ULong = 100uL

    val floatNum: Float = 3.14f
    val doubleNum: Double = 2.71828

    val charLetter: Char = 'A'
    val text: String = "Hello Kotlin"

    // 2. 简单测试代码（每种类型做一次基本操作）
    val boolTest = !bool && false

    val byteTest: Byte = (byteNum + 1).toByte()
    val shortTest: Short = (shortNum + 2).toShort()
    val intTest: Int = intNum * 2
    val longTest: Long = longNum + 1L

    val uByteTest: UByte = (uByteNum.toUInt() + 1u).toUByte()
    val uShortTest: UShort = (uShortNum.toUInt() + 1u).toUShort()
    val uIntTest: UInt = uIntNum + 1u
    val uLongTest: ULong = uLongNum * 2uL

    val floatTest: Float = floatNum + 0.001f
    val doubleTest: Double = doubleNum + 0.001

    val nextChar: Char = (charLetter.code + 1).toChar()
    val upperText: String = text.uppercase()

    // 3. 输出每一项的测试结果
    fun printResult(name: String, original: Any?, tested: Any?) {
        println("[$name] 原值=$original (${original?.let { it::class.simpleName }}) -> 测试值=$tested")
    }

    printResult("Boolean", bool, boolTest)

    printResult("Byte", byteNum, byteTest)
    printResult("Short", shortNum, shortTest)
    printResult("Int", intNum, intTest)
    printResult("Long", longNum, longTest)

    printResult("UByte", uByteNum, uByteTest)
    printResult("UShort", uShortNum, uShortTest)
    printResult("UInt", uIntNum, uIntTest)
    printResult("ULong", uLongNum, uLongTest)

    printResult("Float", floatNum, floatTest)
    printResult("Double", doubleNum, doubleTest)

    printResult("Char", charLetter, nextChar)
    printResult("String", text, upperText)

    println("===== 结束 =====")


    // 定义多行文本并打印
    var food = """
        一碗猪脚饭
        吃出男人的浪漫
    """.trimIndent()

    // .trimIndent() 去换行 空格
    println(food)

    // 模版字符串中 写逻辑代码的示例
    var price = 18
    var totalPrice = "两碗猪脚饭打八折，共${price * 2 * 0.8}元"
    println(totalPrice)


}
